function smallestSym = removeSymmetry(board)
    %construct all 8 symmetry vectors, return smallest
    min_candidates = [true; true; true; true; true; true; true; true];
    symmetries = zeros(8,64); %8 different representations of same board
    
    %fill symmetries and keep track of smallest:
    for i=1:8;
        for j=1:8;
            %calculate the symmetries by walking in 8 different directions
            next_step = syms(i,j);
            for s = 1:8;
                symmetries(s,pos(i,j)) = board(next_step(1,s),next_step(2,s));
            end
            %calculate the minimum over all remaining candidates
            m = min(symmetries(min_candidates, pos(i,j)));
            
            %remove all candidates with value larger than min
            min_candidates(symmetries(:, pos(i,j)) > m) = false;
        end
    end
    %Some rows in the symmetry matrix could be the same
    %(e.g. 1 stone in the corner)
    idxs = find(min_candidates); 
    idx = idxs(1); %return just 1 board
    smallestSym = symmetries(idx, :)'; %as a column-vector
end

function s = syms(i,j)
    %create the 8 symmetric positions in vector notation
    %syms: R^2 |---> R^2 x R^8; symmetric positions in matrix-notation
    s = [i, j, 9-i, j,   9-j, i,   9-i, 9-j; ...
         j, i, j,   9-i, i,   9-j, 9-j, 9-i];
                 
	%s = pos(symmetric_pos(1, :), symmetric_pos(2, :));
end

function p = pos(i, j)
    %mapping from matrix to vector
    %pos: R^2 |---> R
    p = (i - 1) * 8 + j; 
end

